//-
//- Copyright (c) Microsoft. All rights reserved.
//- Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-

extends layout

block js_doc_ready
  | try {
  | if (initializeManageFilter !== undefined) { initializeManageFilter() }
  | if (initializeMembershipFilter !== undefined) { initializeMembershipFilter() }
  | } catch(ex) {};

block content
  - var overview = accountInfo ? accountInfo.overview : null
  div.container
    if onboarding === true
      if user && user.azure
        h1.huge Congratulations, #{user.azure.displayName || user.azure.username}
      else
        h1.huge Congratulations
    else
      //h1
        | Open Source Portal&nbsp;
        small for GitHub
    div.col-md-8
      if accountInfo && onboarding !== true
        if accountInfo.isLinkedUser !== false && accountInfo.twoFactorOn === true
          // No longer showing this UI on the homepage for good states
        else
          div.container
            div.row(style='margin-top:16px')
              // linked membership
              div.col-md-4.col-lg-4.col-sm-4
                if accountInfo.isLinkedUser !== false
                  div.metro-box.ms-blue
                    a(href='/unlink')
                      h3 Linked Identity
                      p= config.brand.companyName.toUpperCase()
                else
                  div.metro-box.ms-light-gray
                    a(href='/link')
                      h3 Not linked
                      p= config.brand.companyName.toUpperCase()
              // 2-factor authentication
              if accountInfo.twoFactorOff === true || accountInfo.twoFactorOn === true
                div.col-md-4.col-lg-4.col-sm-4
                  if accountInfo.twoFactorOff === true
                    div.metro-box.ms-red
                      a(href=activeOrgUrl + 'security-check')
                        h3 2FA
                        p AT RISK
                  else if accountInfo.twoFactorOn === true
                    div.metro-box.ms-green
                      a(href=activeOrgUrl + 'security-check')
                        h3 2-factor auth
                        p PROTECTED

      if onboarding !== true && overview && overview.organizations.member && overview.organizations.member.length
        h1
          a.a-unstyled(name='orgs') Your #{config.brand.companyName} GitHub organizations
      else
        h3 You've successfully linked your #{config.brand.companyName} and GitHub accounts.

      - var currentPriority = ''
      each o in overview.organizations.member
          div.link-box
            a(href=o + onboardingPostfixUrl)
              h2: strong= o
                //-else if o.membershipStateTemporary === 'pending'
                  small
                    span.label.label-danger Membership pending
              - var oo = getOrg(o)
              if oo.description
                p.lead= oo.description

      if onboarding === true
        h3 Your onboarding progress
        h5
          | Sign in to your GitHub &amp; #{config.brand.companyName} accounts&nbsp;
          i.glyphicon.glyphicon-ok
        h5
          | Link your accounts&nbsp;
          i.glyphicon.glyphicon-ok
        h5.text-primary
          | Join your first GitHub organization
        h5
          | Multifactor security checkup
        h5
          | Profile review
        h5
          | Publish your membership <em>(optional)</em>
        h5
          | Join a team <em>(optional)</em>

      //-if accountInfo.isSudoer
        h1 Organization Administration
        p Your account is a delegate administrator for the organization. You have additional capabilities enabled to help ensure the health of the organization.
        p
          a.btn.btn-default(href='/organization') Organization Delegate Dashboard

      if overview.teams.maintainer && overview.teams.maintainer.length
        if accountInfo.pendingApprovals && accountInfo.pendingApprovals.length && accountInfo.pendingApprovals.length > 0
          h1 Approvals: Please Review
          p
            a.btn.btn-default(href='/approvals/') See all pending approvals (#{accountInfo.pendingApprovals.length})

        if overview.teams.maintainer
          h1 Teams you maintain
          div
            table.table#manage-table
              thead
                tr
                  th GitHub name
                  th Organization
                  th Actions
              tbody
                each team in overview.teams.maintainer
                  tr
                    td
                      a.btn.btn-sm.btn-muted(href='/' + team.organization.login + '/teams/' + team.slug)= team.name
                    td.twentypercent= team.organization.login
                    td.thirtypercent
                      ul.list-unstyled
                        li: a.btn.btn-sm.btn-default(href='/' + team.organization.login + '/teams/' + team.slug) Manage
                        //-li: a.btn.btn-sm.btn-muted(href='https://github.com/orgs/' + team.organization.login + '/teams/' + team.slug, target='_new') GitHub

      if accountInfo.isLinkedUser && onboarding !== true
        if overview.teams && overview.teams.member && overview.teams.member.length
          h1 Team memberships
          p Here are teams that you are a member of but not a maintainer of.
          table.table#membership-table
            thead
              tr
                th Team
                th Organization
                th Actions
            tbody
              each team in overview.teams.member
                if team.id && accountInfo.teamsMaintainedHash && accountInfo.teamsMaintainedHash[team.id] !== undefined
                  // Skipping this team since they are already maintaining it
                else
                  tr
                    td
                      a.btn.btn-sm.btn-muted(href='/' + team.organization.login + '/teams/' + team.slug, target='_new')= team.name
                      //-a.btn.btn-sm.btn-muted(href='https://github.com/orgs/' + team.organization.login + '/teams/' + team.slug, target='_new')= team.name
                    td.twentypercent= team.organization.login
                    td.twentypercent
                      p
                        if config.github.teamEveryoneId == team.id
                          a.btn.btn-default.btn-sm(href='/' + team.organization.login + '/leave') Leave Organization
                        else
                          //-a.btn.btn-default.btn-sm(href='https://github.com/orgs/' + team.organization.login + '/teams/' + team.slug, target='_new')
                          a.btn.btn-default.btn-sm(href='/' + team.organization.login + '/teams/' + team.slug, target='_new')
                            | Open on GitHub
          //- The user will get a better experience joining teams if they go through the organization onboarding first.
          //-p
            a.btn.btn-default(href='/teams')= (accountInfo.userTeamMemberships && accountInfo.userTeamMemberships.length && accountInfo.userTeamMemberships.length > 0) ? 'Join another team' : 'Join a team'
        else
          //-p You are not currently a member of any GitHub teams that grant you permission to specific repositories. Note that this display is cached and may not be up-to-date.
    div.col-md-4
      if overview.organizations.available && overview.organizations.available.length
        h2 Available #{config.brand.companyName} GitHub organizations
        .right
          if onboarding === true
            p Join these #{config.brand.companyName} organizations to see private repos and get elevated privileges.

          - var currentPriority = ''
          if groupedAvailableOrganizations
            each list, groupType in groupedAvailableOrganizations
              if groupType === 'secondary'
                hr
                h5 Additional Organizations
                p.small The following organizations are specialized for specific teams and projects, but not general-purpose membership. Please only join if you have a business need.
              each o in list
                //-if o.membershipStateTemporary !== 'active' && o.membershipStateTemporary !== 'pending'
                if o.priority !== currentPriority
                  - currentPriority = o.priority
                  //-if currentPriority == 'secondary'
                //-if o.locked === true // o.membershipStateTemporary !== 'active'
                if o.locked === true
                  //- Do not show by invitation only orgs at this time
                else
                  div.link-box
                    a(href='/' + o.name + '/join' + onboardingPostfixUrl)
                      if groupType === 'secondary'
                        h6.text-muted
                          strong= o.name + ' '
                          small: span.label.label-muted Join
                        p.small.text-mute= o.description
                      else
                        h4
                          = o.name + ' '
                          small: span.label.label-primary Join
                        p.small(style='color:#333')= o.description
